package com.yinhe.music.yhmusic.model;

import android.graphics.Bitmap;

import com.google.gson.annotations.SerializedName;
import com.yinhe.music.yhmusic.constants.IConstants;
import com.yinhe.music.yhmusic.db.bean.RecentMusicDBEntity;
import com.yinhe.music.yhmusic.db.bean.SongDBEntity;
import com.yinhe.music.yhmusic.downmusic.DownloadStatus;
import com.yinhe.music.yhmusic.utils.FileUtils;

import java.io.Serializable;
import java.util.List;

/**
 * 单曲信息
 * Created by wcy on 2015/11/27.
 */
public class Music implements Serializable {

    public long albumId;
    public String albumName;
    private int collectNum;
    private int commentNum;
    private int collectStatus;
    public String image;
    public String lyric;
    private int nationalType;
    private int playNum;
    public float price;
    private List<String> qualityType;
    public int singerId;
    public String singerName;
    public long songId;
    private String songName;
    private int downloadNum;
    private int purchaseStatus;
    private String qualityLevel;
    private int movieId;
    private int vipPurchaseSongLimit;
    private int vipPurchaseSong;

    @SerializedName(value = "songList", alternate = {"purchaseSongList"})
    private List<Music> songList;
    private String songListStr;
    private int pageNum;
    private String lyricCode;

    //local
    public String url;
    public String filePath;
    private boolean isLocalMusic;
    private List<Music> songs;
    private Music song;
    //old
    public String lang;
    public int level;
    public Type fileType;
    private boolean isChecked;
    private String quality;

    public Music(String songName) {
        this.songName = songName;
    }

    public Music(List<Music> songList, int pageNum) {
        this.songList = songList;
        this.pageNum = pageNum;
    }

    public int getVipPurchaseSongLimit() {
        return vipPurchaseSongLimit;
    }

    public void setVipPurchaseSongLimit(int vipPurchaseSongLimit) {
        this.vipPurchaseSongLimit = vipPurchaseSongLimit;
    }

    public int getVipPurchaseSong() {
        return vipPurchaseSong;
    }

    public void setVipPurchaseSong(int vipPurchaseSong) {
        this.vipPurchaseSong = vipPurchaseSong;
    }

    public int getMovieId() {
        return movieId;
    }

    public void setMovieId(int movieId) {
        this.movieId = movieId;
    }

    public String getSongListStr() {
        return songListStr;
    }

    public void setSongListStr(String songListStr) {
        this.songListStr = songListStr;
    }

    public int getPurchaseStatus() {
        return purchaseStatus;
    }

    public void setPurchaseStatus(int purchaseStatus) {
        this.purchaseStatus = purchaseStatus;
    }

    public int getCollectNum() {
        return collectNum;
    }

    public void setCollectNum(int collectNum) {
        this.collectNum = collectNum;
    }

    public int getCollectStatus() {
        return collectStatus;
    }

    public void setCollectStatus(int collectStatus) {
        this.collectStatus = collectStatus;
    }

    public int getPlayNum() {
        return playNum;
    }

    public void setPlayNum(int playNum) {
        this.playNum = playNum;
    }

    public List<String> getQualityType() {
        return qualityType;
    }

    public void setQualityType(List<String> qualityType) {
        this.qualityType = qualityType;
    }

    public int getDownloadNum() {
        return downloadNum;
    }

    public void setDownloadNum(int downloadNum) {
        this.downloadNum = downloadNum;
    }

    public List<Music> getSongList() {
        return songList;
    }

    public void setSongList(List<Music> songList) {
        this.songList = songList;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public Music getSong() {
        return song;
    }

    public void setSong(Music song) {
        this.song = song;
    }

    public List<Music> getSongs() {
        return songs;
    }

    public void setSongs(List<Music> songs) {
        this.songs = songs;
    }

    public int getNationalType() {
        return nationalType;
    }

    public void setNationalType(int nationalType) {
        this.nationalType = nationalType;
    }

    public int getCommentNum() {
        return commentNum;
    }

    public void setCommentNum(int commentNum) {
        this.commentNum = commentNum;
    }

    public boolean isLocalMusic() {
        return isLocalMusic;
    }

    public void setLocalMusic(boolean localMusic) {
        isLocalMusic = localMusic;
    }

    public String getLyricCode() {
        return lyricCode;
    }

    public void setLyricCode(String lyricCode) {
        this.lyricCode = lyricCode;
    }

    public int getRadioId() {
        return radioId;
    }

    public void setRadioId(int radioId) {
        this.radioId = radioId;
    }

    private int radioId;

    public boolean isRadio() {
        return isRadio;
    }

    public void setRadio(boolean radio) {
        isRadio = radio;
    }

    private boolean isRadio = false;


    public int downloadStatus = DownloadStatus.DOWNLOAD_STATUS_ONLINE;

    public Bitmap cover;
    public long duration;

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public long getSongId() {
        return songId;
    }

    public void setSongId(long songId) {
        this.songId = songId;
    }

    public String getSongName() {
        return songName;
    }

    public void setSongName(String songName) {
        this.songName = songName;
    }

    public String getQuality() {
        if (quality != null) {
            return quality;
        } else {
            return IConstants.Common;
        }

    }

    public void setQuality(String quality) {
        this.quality = quality;
    }

    public long getAlbumId() {
        return albumId;
    }

    public void setAlbumId(long albumId) {
        this.albumId = albumId;
    }

    public String getAlbumName() {
        return albumName;
    }

    public void setAlbumName(String albumName) {
        this.albumName = albumName;
    }

    public int getSingerId() {
        return singerId;
    }

    public void setSingerId(int singerId) {
        this.singerId = singerId;
    }

    public String getSingerName() {
        return singerName;
    }

    public void setSingerName(String singerName) {
        this.singerName = singerName;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getLang() {
        return lang;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    public String getLyric() {
        return lyric;
    }

    public void setLyric(String lyric) {
        this.lyric = lyric;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getQualityLevel() {
        return qualityLevel;
    }

    public void setQualityLevel(String qualityLevel) {
        this.qualityLevel = qualityLevel;
    }

    public enum Type {
        LOCAL,
        ONLINE
    }

    public long getId() {
        return songId;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getCoverUri() {
        return image;
    }

    public Type getFileType() {
        return fileType;
    }

    public void setFileType(Type fileType) {
        this.fileType = fileType;
    }

    public String getArtist() {
        return singerName;
    }

    public String getTitle() {
        return songName;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getFileName() {
        return FileUtils.getMp3FileName(singerName, songName);
    }

    public Bitmap getCover() {
        return cover;
    }

    public void setCover(Bitmap cover) {
        this.cover = cover;
    }

//    public String getMediaID() {
//        return mediaID;
//    }
//
//    public void setMediaID(String mediaID) {
//        this.mediaID = mediaID;
//    }

    public String getUrl() {

        return url;
    }


    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public int getDownloadStatus() {
        return downloadStatus;
    }

    public void setDownloadStatus(int down) {
        downloadStatus = down;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null) {
            return false;
        }
        if (getClass() != o.getClass()) {
            return false;
        }
        final Music music = (Music) o;
        if (this.getSongId() != music.getSongId()) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int result = (int) (songId ^ (songId >>> 32));
        result = 31 * result + (int) (albumId ^ (albumId >>> 32));
        result = 31 * result + singerId;
        return result;
    }

    public Music(RecentMusicDBEntity recentMusicDBEntity) {
        this.albumId = recentMusicDBEntity.albumid;
        this.albumName = recentMusicDBEntity.albumname;
        this.image = recentMusicDBEntity.image;
        this.lyric = recentMusicDBEntity.lyrics;
        this.singerId = recentMusicDBEntity.singerid;
        this.singerName = recentMusicDBEntity.singername;
        this.songId = recentMusicDBEntity.songid;
        this.songName = recentMusicDBEntity.songname;
        this.filePath = recentMusicDBEntity.getUri();
        this.url = recentMusicDBEntity.getUrl();
        this.downloadStatus = recentMusicDBEntity.downloadStatus;
        this.isRadio = recentMusicDBEntity.isRadio();
        this.quality = recentMusicDBEntity.getQtype();
        this.isRadio = recentMusicDBEntity.isRadio;
        this.radioId = recentMusicDBEntity.radioId;
        this.lyricCode = recentMusicDBEntity.getLyricsCode();
        this.qualityLevel = recentMusicDBEntity.getQuality();
    }

    public Music(SongDBEntity songDB) {
        this.setSongId(songDB.getSongid());
        this.setSongName(songDB.getSongname());
        this.setSingerId(songDB.getSingerid());
        this.setSingerName(songDB.getSingername());
        this.setAlbumId(songDB.getAlbumid());
        this.setAlbumName(songDB.getAlbumname());
        this.setLyric(songDB.getLyrics());
        this.setUrl(songDB.getUrl());
        this.setFilePath(songDB.getUri());
        this.setFileType(songDB.getFile_type());
        this.setPrice(songDB.getPrice());
        this.setLang(songDB.getLang());
        this.setLevel(songDB.getLevel());
        this.setImage(songDB.getImage());
        this.setFilePath(songDB.getUri());
        this.setRadioId(songDB.radioId);
        this.setRadio(songDB.isRadio);
        this.setLyricCode(songDB.getLyricsCode());
        this.setNationalType(songDB.getSysmusiclang());
        this.setQuality(songDB.getQtype());
        this.setQualityLevel(songDB.getQuality());
        this.setLocalMusic(songDB.isSyn());
    }

    public Music(RadioListInfo.RadioSongs radioSongs, int radioId) {
        this.songId = radioSongs.getRadiosongid();
        this.songName = radioSongs.getName();
        this.image = radioSongs.getImage();
        this.singerName = radioSongs.getUsername();
        this.radioId = radioId;
        this.isRadio = true;
        this.commentNum = radioSongs.getCommentNum();
    }

    public Music() {

    }
    //比较方法,返回值boolean
    public boolean isIncluded(Music music) {
        if(music == null) {
            return false; //如果传入null===》返false
        }
        if(this == music) {
            return true; //如果是自己===》返true
        }
        return false; //其他情况 即连个对象不相等===》返false
    }
}
